﻿/*
Commerce by Onex – eCommerce software platform (www.ecommerce.byonex.com)
Copyright (C) 2008-2010 by Onex Group

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Reflection;

namespace ShopModel
{
    /// <summary>
    /// Klasa opisująca Vouchera.
    /// (Class describing Voucher.)
    /// </summary>
    public class Voucher
    {
        #region Variables

        int idVoucher;
        string code;
        VoucherType type;
        DateTime date;
        decimal? value;
        decimal acceptValue;
        int? customerId;
        bool used;
        int? generatedRealizationId;
        int? usedRealizationId;

        #endregion Variables

        #region Fields

        public int IdVoucher
        {
            get { return idVoucher; }
            set { idVoucher = value; }
        }

        public string Code
        {
            get { return code.Insert(4,"-"); }
            set { code = value.Replace("-","").Substring(0,8); }
        }

        public VoucherType Type
        {
            get { return type; }
            set { type = value; }
        }

        public DateTime Date
        {
            get { return date; }
            set { date = value; }
        }

        public decimal? Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        public decimal AcceptValue
        {
            get { return acceptValue; }
            set { acceptValue = value; }
        }

        public int? CustomerId
        {
            get { return customerId; }
            set { customerId = value; }
        }

        public bool Used
        {
            get { return used; }
            set { used = value; }
        }

        public int? GeneratedRealizationId
        {
            get { return generatedRealizationId; }
            set { generatedRealizationId = value; }
        }
        
        public int? UsedRealizationId
        {
            get { return usedRealizationId; }
            set { usedRealizationId = value; }
        }


        public string TypeString
        {
            get
            {
                ResourceManager rm = new ResourceManager("Resources.Language", Assembly.Load("App_GlobalResources"));
                switch (type)
                {
                    case VoucherType.FreeShipment: return rm.GetString("FreeShipment");
                    case VoucherType.Percent: return rm.GetString("PercentVoucher");
                    case VoucherType.Value: return rm.GetString("ValueVoucher");
                    default: return rm.GetString("Unknown");
                }
            }
        }

        #endregion Fields
    }

    public enum VoucherType { FreeShipment=1, Percent=2, Value=3}
}
